package cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/write")
public class WriteCookieServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//1.创建Cookie
		Cookie c1 = new Cookie("name","lisi");
		Cookie c2 = new Cookie("age","20");  
		//2.设置cookie在客户端的生命期
		// 默认的生命周期是session（关闭浏览器就失效）
		c1.setMaxAge(3600); // 60*60 = 3600秒=1小时
		//3.响应体中添加cookie
		resp.addCookie(c1);
		resp.addCookie(c2);
	}
}
